package cn.gson.work.controller;

import cn.gson.work.model.pojos.Dept;
import cn.gson.work.model.pojos.Position;
import cn.gson.work.model.pojos.User;
import cn.gson.work.model.service.DeptService;
import cn.gson.work.model.service.PositionService;
import cn.gson.work.model.service.UserService;
import cn.gson.work.model.vo.DeptQuery;
import cn.gson.work.model.vo.DeptTree;
import cn.gson.work.model.vo.PositionQuery;
import cn.gson.work.model.vo.UserQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
public class SysController {
    @Autowired
    UserService users;
    @Autowired
    DeptService depts;
    @Autowired
    PositionService pos;

    /**
     * 根据条件查询用户信息
     * @param query
     * @return
     */
    @RequestMapping("/getUser")
    public Map<String,Object> getUserByQuery(@RequestBody UserQuery query){
        System.out.println(query.toString());
       return users.getUserByQuery(query);
    }

    /**
     * 新增用户信息
     * @param user
     */
    @RequestMapping("/addUser")
    public void addUser(@RequestBody User user){
        System.out.println(user.toString());
        users.addUser(user);
    }

    /**
     * 修改用户信息
     * @param user
     */
    @RequestMapping("/editUser")
    public void editUser(@RequestBody User user){
        users.editUser(user);
    }


    @RequestMapping("/getDeptList")
    public Map<String,Object> getDeptList(@RequestBody DeptQuery query){
        return depts.getDeptList(query);
    }

    /**
     *根据条件查询部门信息
     * @param query
     * @return
     */
    @RequestMapping("/getDept")
    public Map<String,Object> getDept(@RequestBody DeptQuery query){
        return depts.getDept(query);
    }

    @RequestMapping("/getSortDeptList")
    public List<DeptTree> getSortBrList(@RequestBody DeptQuery query){
        System.out.println(query.toString());
        return depts.getSortDeptList(query);
    }

    /**
     * 根据条件查询职位信息
     * @param query
     * @return
     */
    @RequestMapping("/getposition")
    public Map<String,Object> getPosition(@RequestBody PositionQuery query){
        return pos.getPosition(query);
    }

    /**
     * 新增职位信息
     * @param position
     */
    @RequestMapping("/addposition")
    public void addPosition(@RequestBody Position position){
        pos.addPosition(position);
    }

    /**
     * 修改职位信息
     * @param position
     */
    @RequestMapping("/editposition")
    public void editPosition(@RequestBody Position position){
        pos.editPosition(position);
    }

    /**
     * 新增部门
     * @param dept
     */
    @RequestMapping("/addDept")
    public void addDept(@RequestBody Dept dept){
        depts.addDept(dept);
    }

    /**
     * 修改部门信息
     * @param dept
     */
    @RequestMapping("/editDept")
    public void editDept(@RequestBody Dept dept){
        depts.editDept(dept);
    }

    }
